<template>
  <a-modal :title="title" :width="800" :visible="visible" :confirmLoading="confirmLoading" switchFullscreen @ok="handleOk" @cancel="handleCancel" cancelText="关闭">

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-row>
          <a-col :span="12">
            <div class="title">基础信息</div>
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="工号">
              <a-input :disabled=true v-model="record.workNo" />
            </a-form-item>
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="姓名">
              <a-input :disabled=true v-model="record.realname" />
            </a-form-item>
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="归属部门">
              <a-input :disabled=true v-model="record.departName" />
            </a-form-item>
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="岗位">
              <a-input :disabled=true v-model="record.roleName" />
            </a-form-item>
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="备注">
              <a-textarea placeholder="请填写备注内容" v-model="record.remark" />
            </a-form-item>

          </a-col>
          <a-col :span="12">
            <div class="title">绩效设置</div>
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="岗位绩效">
              <div v-for="item in record.performanceConfigModelList">
                <a-checkbox v-model="item.isSelect"></a-checkbox>
                <span style="margin-left: 5px"> {{item.name+'('+item.score+')'}}</span>
              </div>
            </a-form-item>
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="固定薪资">
              <a-radio-group :options="plainOptions" :default-value="record.fixType" v-model="record.fixType" @change="onSelectFixedWages" />
              <a-input v-model="record.fixSalary" v-if="showFixedWages" />
            </a-form-item>
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="基础薪资">
              {{baseFixedWages}}
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>

    </a-spin>
  </a-modal>
</template>
<script>
import { getAction, httpAction } from '@/api/manage'
import pick from 'lodash.pick'
import moment from 'moment'
import { validateDuplicateValue } from '@/utils/util'

export default {
  name: 'UserPerModal',
  data() {
    return {
      record: {},
      title: '员工信息',
      visible: false,
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      form: this.$form.createForm(this),
      confirmLoading: false,
      url: {
        add: '/pump/pumpStation/add',
        edit: '/pump/pumpStation/edit'
      },
      plainOptions: [{ label: '启用', value: 1 }, { label: '不启用', value: 2 }],
      showFixedWages: false
    }
  },
  methods: {
    edit(record) {
      this.record = record
      this.visible = true
      if (this.record.performanceType == null) {
        this.record.performanceType = 1
      }
      if (this.record.value == null) {
        this.record.value = 0
      }
      if (this.record.fixSalary == null) {
        this.record.fixSalary = 0
      }
      if (this.record.fixType == null) {
        this.record.fixType = 2
      }
      this.showFixedWages = this.record.fixType == 1
    },
    close() {
      this.$emit('ok')
      this.visible = false
    },

    handleOk() {
      const that = this
      if (this.record.fixType == 1 && this.record.fixSalary == 0) {
        this.$message.error('固定薪资必须填写大于0')
        return false
      }
      httpAction('/performance/performanceUser/edit', this.record, 'put').then(res => {
        if (res.success) {
          this.$message.success(res.message)
          this.$emit('ok')
          this.visible = false
        } else {
          this.$message.warning(res.message)
        }
      })
    },
    handleCancel() {
      this.close()
    },

    countJiaQuan() {
      var list = this.record.performanceConfigModelList
      var total = 0
      for (var i = 0; i <= list.length - 1; i++) {
        if (list[i].isSelect) {
          total = Number(total) + Number(list[i].score)
        }
      }
      if (this.record.performanceType == 1) {
        //this.record.postValue =  Number(this.record.postValue)- Number(this.record.value)
        this.record.performanceValue = Number(total) - Number(this.record.value)
      } else {
        // this.record.postValue =  Number(this.record.postValue)+ Number(this.record.value)
        this.record.performanceValue = Number(total) + Number(this.record.value)
      }
    },
    onSelectFixedWages(e) {
      this.showFixedWages = e.target.value == '1'
    }
  },
  created() {},
  computed: {
    baseFixedWages() {
      var total = 0
      if (this.record.performanceConfigModelList != undefined) {
        this.record.performanceConfigModelList.forEach(item => {
          if (item.isSelect) {
            total += Number(item.score)
          }
        })
      }
      if (this.record.fixType == '1') {
        total += Number(this.record.fixSalary)
      }
      return total
    }
  }
}
</script>

<style lang="less" scoped>
.list {
  display: flex;
  align-items: center;
}
.title {
  color: #333;
  font-size: 14px;
  font-weight: bold;
  margin-bottom: 5px;
}
.ant-form-item {
  margin-bottom: 3px;
}
/deep/.search-box-wrapper {
  background-color: #ededed;
  input {
    background-color: #ededed;
  }
}
.search-box {
  margin-bottom: 10px;
}
.address {
  padding-top: 10px;
  span:nth-child(1) {
    color: #333;
    font-weight: bold;
    margin-right: 10px;
  }
}
</style>
